package com.lq.educationsystem.admin.service.impl;

import com.lq.educationsystem.admin.entiy.AdminTb;
import com.lq.educationsystem.admin.mapper.AdminTbMapper;
import com.lq.educationsystem.admin.service.AdminService;
import com.lq.educationsystem.common.util.Result;
import com.lq.educationsystem.common.util.ResultBuild;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    AdminTbMapper adminTbMapper;
    @Override
    public Result login(AdminTb adminInfo) {
        String adminAccount = adminInfo.getAdminAccount();
        //调用mapper
        AdminTb querAdminInfo = adminTbMapper.queryInfoByAccount(adminAccount);
        //判断并且设置返回结果
        if( querAdminInfo.getAdminAccount().equals(adminInfo.getAdminAccount())){
            //账号存在
                //判断密码是否正确
            if(querAdminInfo.getAdminPassword().equals(adminInfo.getAdminPassword())){
                //密码正确
                return ResultBuild.buildOk(new Result<>(),querAdminInfo);
            }else{
                //密码不正确
                Result result = ResultBuild.buildDefeat();
                result.setMessage("密码错误");
                return result;
            }
        }else{
            //账号不存在
            Result result = ResultBuild.buildDefeat();
            result.setMessage("账号不存在");
            return result;
        }


    }
}
